#-*-coding:utf-8-*-
import maya.cmds as cmds

shaderName='aiStandardSurface1_zhongtai_model_v002'
def getSurfaceAttrDict(shaderName):
    matAttr={}
    #Base
    base=cmds.getAttr(shaderName+'.base')
    baseColor=cmds.getAttr(shaderName+'.baseColor')[0]
    diffuseRoughness=cmds.getAttr(shaderName+'.diffuseRoughness')
    metalness=cmds.getAttr(shaderName+'.metalness')
    matAttr['base']=base
    matAttr['base_color']=baseColor
    matAttr['diffuse_roughness']=diffuseRoughness
    matAttr['metalness']=metalness
    #Specular
    specular=cmds.getAttr(shaderName+'.specular')
    specularColor=cmds.getAttr(shaderName+'.specularColor')[0]
    specularRoughness=cmds.getAttr(shaderName+'.specularRoughness')
    specularIOR=cmds.getAttr(shaderName+'.specularIOR')
    specularAnisotropy=cmds.getAttr(shaderName+'.specularAnisotropy')
    specularRotation=cmds.getAttr(shaderName+'.specularRotation')
    matAttr['specular']=specular
    matAttr['specular_color']=specularColor
    matAttr['specular_roughness']=specularRoughness
    matAttr['specular_IOR']=specularIOR
    matAttr['specular_anisotropy']=specularAnisotropy
    matAttr['specular_rotation']=specularRotation
    #Transmission
    transmission=cmds.getAttr(shaderName+'.transmission')
    transmissionColor=cmds.getAttr(shaderName+'.transmissionColor')[0]
    transmissionDepth=cmds.getAttr(shaderName+'.transmissionDepth')
    transmissionScatter=cmds.getAttr(shaderName+'.transmissionScatter')[0]
    transmissionScatterAnisotropy=cmds.getAttr(shaderName+'.transmissionScatterAnisotropy')
    transmissionDispersion=cmds.getAttr(shaderName+'.transmissionDispersion')
    transmissionExtraRoughness=cmds.getAttr(shaderName+'.transmissionExtraRoughness')
    matAttr['transmission']=transmission
    matAttr['transmission_color']=transmissionColor
    matAttr['transmission_depth']=transmissionDepth
    matAttr['transmission_scatter']=transmissionScatter
    matAttr['transmission_scatter_anisotropy']=transmissionScatterAnisotropy
    matAttr['transmission_dispersion']=transmissionDispersion
    matAttr['transmission_extra_roughness']=transmissionExtraRoughness
    #subsurface
    subsurface=cmds.getAttr(shaderName+'.subsurface')
    subsurfaceColor=cmds.getAttr(shaderName+'.subsurfaceColor')[0]
    subsurfaceRadius=cmds.getAttr(shaderName+'.subsurfaceRadius')[0]
    subsurfaceScale=cmds.getAttr(shaderName+'.subsurfaceScale')
    subsurfaceTypeValue=cmds.getAttr(shaderName+'.subsurfaceType') #这里0 对应diffusion  1对应randomwalk
    subsurfaceType='diffusion' if subsurfaceTypeValue==0 else 'randomwalk'
    subsurfaceAnisotropy=cmds.getAttr(shaderName+'.subsurfaceAnisotropy')
    matAttr['subsurface']=subsurface
    matAttr['subsurface_color']=subsurfaceColor
    matAttr['subsurface_radius']=subsurfaceRadius
    matAttr['subsurface_scale']=subsurfaceScale
    matAttr['subsurface_type']=subsurfaceType
    matAttr['subsurface_anisotropy']=subsurfaceAnisotropy
    #Coat
    coat=cmds.getAttr(shaderName+'.coat')
    coatColor=cmds.getAttr(shaderName+'.coatColor')[0]
    coatRoughness=cmds.getAttr(shaderName+'.coatRoughness')
    coatIOR=cmds.getAttr(shaderName+'.coatIOR')
    coatNormal=cmds.getAttr(shaderName+'.coatNormal')[0]
    matAttr['coat']=coat
    matAttr['coat_color']=coatColor
    matAttr['coat_roughness']=coatRoughness
    matAttr['coat_IOR']=coatIOR
    matAttr['coat_normal']=coatNormal
    #Sheen
    sheen=cmds.getAttr(shaderName+'.sheen')
    sheenColor=cmds.getAttr(shaderName+'.sheenColor')[0]
    sheenRoughness=cmds.getAttr(shaderName+'.sheenRoughness')
    matAttr['sheen']=sheen
    matAttr['sheen_color']=sheenColor
    matAttr['sheen_roughness']=sheenRoughness
    #Emission
    emission=cmds.getAttr(shaderName+'.emission')
    emissionColor=cmds.getAttr(shaderName+'.emissionColor')[0]
    matAttr['emission']=emission
    matAttr['emission_color']=emissionColor
    #Geometry
    opacity=cmds.getAttr(shaderName+'.opacity')[0]
    normalCamera=cmds.getAttr(shaderName+'.normalCamera')[0]
    tangent=cmds.getAttr(shaderName+'.tangent')[0]
    matAttr['opacity']=opacity
    matAttr['normal']=normalCamera
    matAttr['tangent']=tangent

    return matAttr


def getCarAttrDict(shaderName):
    matAttr = {}
    # Base
    base = cmds.getAttr(shaderName + '.base')
    baseColor = cmds.getAttr(shaderName + '.baseColor')[0]
    baseRoughness = cmds.getAttr(shaderName + '.baseRoughness')
    matAttr['base'] = base
    matAttr['base_color'] = baseColor
    matAttr['diffuse_roughness'] = diffuseRoughness
    # Specular
    specular = cmds.getAttr(shaderName + '.specular')
    specularColor = cmds.getAttr(shaderName + '.specularColor')[0]
    specularFlipFlop = cmds.getAttr(shaderName + '.specularFlipFlop')[0]
    specularLightFacing = cmds.getAttr(shaderName + '.specularLightFacing')[0]
    specularFalloff = cmds.getAttr(shaderName + '.specularFalloff')
    specularRoughness = cmds.getAttr(shaderName + '.specularRoughness')
    specularIOR = cmds.getAttr(shaderName + '.specularIOR')
    transmissionColor = cmds.getAttr(shaderName + '.transmissionColor')[0]
    matAttr['specular'] = specular
    matAttr['specular_color'] = specularColor
    matAttr['specular_flip_flop'] = specularFlipFlop
    matAttr['specular_light_facing'] = specularLightFacing
    matAttr['specular_falloff'] = specularFalloff
    matAttr['specular_roughness'] = specularRoughness
    matAttr['specular_IOR'] = specularIOR
    matAttr['transmission_color'] = transmissionColor
    # Flakes
    flakeColor = cmds.getAttr(shaderName + '.flakeColor')[0]
    flakeFlipFlop = cmds.getAttr(shaderName + '.flakeFlipFlop')[0]
    flakeLightFacing = cmds.getAttr(shaderName + '.flakeLightFacing')[0]
    flakeFalloff = cmds.getAttr(shaderName + '.flakeFalloff')
    flakeRoughness = cmds.getAttr(shaderName + '.flakeRoughness')
    flakeIOR = cmds.getAttr(shaderName + '.flakeIOR')
    flakeScale = cmds.getAttr(shaderName + '.flakeScale')
    flakeDensity = cmds.getAttr(shaderName + '.flakeDensity')
    flakeLayers = cmds.getAttr(shaderName + '.flakeLayers')
    flakeNormalRandomize = cmds.getAttr(shaderName + '.flakeNormalRandomize')
    flakeCoordSpaceList = ['world', 'object', 'pref', 'uv']
    flakeCoordSpaceIndex = cmds.getAttr(shaderName + '.flakeCoordSpace')
    flakeCoordSpace = flakeCoordSpaceList[flakeCoordSpaceIndex]
    matAttr['flake_color'] = flakeColor
    matAttr['flake_flip_flop'] = flakeFlipFlop
    matAttr['flake_light_facing'] = flakeLightFacing
    matAttr['flake_falloff'] = flakeFalloff
    matAttr['flake_roughness'] = flakeRoughness
    matAttr['flake_IOR'] = flakeIOR
    matAttr['flake_scale'] = flakeScale
    matAttr['flake_density'] = flakeDensity
    matAttr['flake_layers'] = flakeLayers
    matAttr['flake_normal_randomize'] = flakeNormalRandomize
    matAttr['flake_coord_space'] = flakeCoordSpace
    # Coat
    coat = cmds.getAttr(shaderName + '.coat')
    coatColor = cmds.getAttr(shaderName + '.coatColor')[0]
    coatRoughness = cmds.getAttr(shaderName + '.coatRoughness')
    coatIOR = cmds.getAttr(shaderName + '.coatIOR')
    flakeRoughness = cmds.getAttr(shaderName + '.flakeRoughness')
    coatNormal = cmds.getAttr(shaderName + '.coatNormal')[0]
    matAttr['coat'] = coat
    matAttr['coat_color'] = coatColor
    matAttr['coat_roughness'] = coatRoughness
    matAttr['coat_IOR'] = coatIOR
    matAttr['flake_roughness'] = flakeRoughness
    matAttr['coat_normal'] = coatNormal

    return matAttr